#include "stdafx.h"
#include "CppUnitTest.h"
#include "..\CppAlgorithms\CppAlgorithmsHeader.h"
#include <stdio.h>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace CppAlgorithms
{		
	TEST_CLASS(UnitTest1)
	{
	public:
		
		TEST_METHOD(TestMethod1)
		{
			char* str = "hello world";
			Assert::AreEqual("helo wrd", CppAlgorithms::RemoveDuplicateFromString(str), true);
		}

		TEST_METHOD(Test_SingleChar)
		{
			char* str = "h";
			Assert::AreEqual("h", CppAlgorithms::RemoveDuplicateFromString(str), true);
		}

		TEST_METHOD(Test_EmptyString)
		{
			char* str = "";
			Assert::AreEqual("", CppAlgorithms::RemoveDuplicateFromString(str), true);
		}

		TEST_METHOD(Test_NullString)
		{
			// THIS test fails at strlen(str) when str = NULL, strlen could not handle this situation
			char * str = NULL;
			Assert::AreEqual(NULL, CppAlgorithms::RemoveDuplicateFromString(str), true);
			
		}

		TEST_METHOD(Test_allDuplicate)
		{
			char* str = "aaaa";
			Assert::AreEqual("a", CppAlgorithms::RemoveDuplicateFromString(str), true);
		}

		TEST_METHOD(Test_NoDuplicate)
		{
			char* str = "abcd";
			Assert::AreEqual("abcd", CppAlgorithms::RemoveDuplicateFromString(str), true);
		}

		TEST_METHOD(Test_ContinuousDuplicate)
		{
			char* str = "aabbcc";
			Assert::AreEqual("abc", CppAlgorithms::RemoveDuplicateFromString(str), true);
		}

		TEST_METHOD(Test_anagram_yes)
		{
			char* str1 = "abc";
			char* str2 = "cab";
		
			Assert::IsTrue(CppAlgorithms::isAnagram(str1, str2));
		}

		TEST_METHOD(Test_anagram_no)
		{
			char* str1 = "abc";
			char* str2 = "abe";

			Assert::IsFalse(CppAlgorithms::isAnagram(str1, str2));
		}

		TEST_METHOD(Test_permut_ABC)
		{
			char str1[] = "abcde";

			vector<char*> permutations = CppAlgorithms::permut(str1, 5);

			Assert::AreEqual<int>(120, (int)(permutations.size()), L"Verify result set size");
		}

		TEST_METHOD(Test_permut_SingleCharacter)
		{
			char str2[] = "a";

			vector<char*> permutations = CppAlgorithms::permut(str2, 1);

			Assert::AreEqual<int>(1, (int)(permutations.size()), L"Verify result set size.");

		}

		TEST_METHOD(Test_permut_SingleSpace)
		{
			char str3[] = " ";
			vector<char*> permutations = CppAlgorithms::permut(str3, 1);

			Assert::AreEqual<int>(0, (int)(permutations.size()), L"Verify result set size.");
		}

		TEST_METHOD(Test_gcd_12_18)
		{
			int a = 12, b=18;
			Assert::AreEqual(6, CppAlgorithms::greatest_common_divisor(a, b), L"Expect result is 6.");
		}

		TEST_METHOD(Test_gcd_2_6)
		{
			int a=2, b=6;
			Assert::AreEqual(2, CppAlgorithms::greatest_common_divisor(a, b), L"Expect result is 2.");
		}

		TEST_METHOD(Test_gcd_0_5)
		{
			int a= 0, b = 5;
			Assert::AreEqual(5, CppAlgorithms::greatest_common_divisor(a, b), L"Expect result is 5");
		}

		TEST_METHOD(Test_gcd_5_5)
		{
			int a = 5, b =5;
			Assert::AreEqual(5, CppAlgorithms::greatest_common_divisor(a,b), L"Expect result is5");
		}

		TEST_METHOD(Test_getSubsets)
		{
			unordered_set<int> input ;
			input.emplace(3);
			input.emplace(2);
			input.emplace(4);
			input.emplace(5);
			input.emplace(15);
			input.emplace(25);
			input.emplace(35);
			input.emplace(45);
			input.emplace(55);
			vector<unordered_set<int>> ret = CppAlgorithms::getSubsets(input);
			wchar_t errormessage[100];
			 swprintf(errormessage, (size_t)100, L"method doesn't return expeted number. Expected %d, actual %d", 511,(int)(ret.size())) ;
			Assert::AreEqual<int>(511, (int)(ret.size()), const_cast<const wchar_t *>(errormessage));																							 

			// test 2
			unordered_set<int> input2 ;
			vector<unordered_set<int>> ret2 = CppAlgorithms::getSubsets(input2);
			Assert::AreEqual(1, (int)(ret2.size()), L"method doesn't return expected number.");
		}
	};
}